<template>
  <div>
    <p class="errorMsg">{{msg}}</p>
    <p>
      <label>用户：</label>
      <input type="text" name="userCode" v-model="userCode">
    </p>
    <p>
      <label>密码：</label>
      <input type="password" name="password" v-model="password">
    </p>
    <p>
      <button @click="login()">登录</button>
    </p>
  </div>
</template>

<script>
export default {
  name: 'LoginApp',
  data () {
    return {
     userCode:'',
     password:'',
     msg:''
    }
  },
  methods: {
    login () {
      this.axios({
       method:'post',
       url:'api/login',
       data:{
         userCode:this.userCode,
         password:this.password
       }
      }).then(rs=>{
       console.log(rs.data)
       if(rs.data.code === 5001){
            this.msg = rs.data.msg
       }else{
            window.sessionStorage.setItem('token',rs.data.token)
            window.sessionStorage.setItem('userName',rs.data.userName)
            this.$router.push('/welcome')
       }
      })
    }
  }
}

</script>

<style lang="css" scoped>
    .errorMsg{
        background-color: hotpink;
        color: red;
    }
</style>